home *** CD-ROM | disk | FTP | other *** search
- /* Definitions for the X11 interface to Xconq.
- Copyright (C) 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995
- Stanley T. Shebs.
-
- Xconq is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version. See the file COPYING. */
-
- /* Default color of text and icons - 0 is for white on black, 1
- is for black on white. Should be set appropriately for the most
- common monochrome display (color displays always do white on black).
- This is also settable by the player, so the default is just for
- convenience of the majority. */
-
- #define BLACKONWHITE 1
-
- #define BARGRAPHS
-
- /* The default fonts can be altered by users, so these are just hints. */
-
- #define TEXTFONT "fixed"
-
- #define ICONFONT "xconq"
- #define STANDARD "standard"
-
- /* Some X11 servers die if too much is written between output flushes. */
-
- /* #define STUPIDFLUSH */
-
- /* This is the name of a family of programs, so argv[0] inadequate. */
-
- #define PROGRAMNAME "xconq"
- #define PROGRAMCLASSNAME "Xconq"
-
- #include <X11/Xos.h>
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- #include <X11/Xresource.h>
-
- #include <X11/Intrinsic.h>
- #include <X11/StringDefs.h>
- #include <X11/Xaw/Box.h>
- #include <X11/Xaw/Form.h>
- #include <X11/Xaw/Paned.h>
- #include <X11/Xaw/Dialog.h>
- #include <X11/Xaw/Label.h>
- #include <X11/Xaw/Command.h>
- #include <X11/Xaw/Toggle.h>
- #include <X11/Xaw/List.h>
- #include <X11/Xaw/AsciiText.h>
- #include <X11/Xaw/Viewport.h>
- #include <X11/Xaw/Panner.h>
- #include <X11/Xaw/Porthole.h>
- #include <X11/Shell.h>
-
- #include <X11/Xaw/Cardinals.h>
- #include <X11/Xaw/Toggle.h>
- #include <X11/Xaw/SmeBSB.h>
-
- #include <math.h>
-
- #include "imf.h"
- #include "ximf.h"
- #include "ui.h"
- /* (not ideal, since only needed here so feature-drawing code is available) */
- #include "print.h"
-
- #ifndef IMFLIB
- #ifdef VMS
- #define IMFLIB "[-.lib-x11]"
- #else /* not VMS */
- #define IMFLIB "../lib-x11"
- #endif /* VMS */
- #endif /* IMFLIB */
-
- enum grayshade {
- gray,
- darkgray,
- numgrays
- };
-
- /* Drawing techniques that may be used. */
-
- enum whattouse {
- dontdraw,
- useblocks,
- usepictures,
- usefontchars,
- usepolygons
- };
-
- /* Types of controls. */
-
- enum controltypeenum {
- LOOK = 0,
- MOVE,
- UNIT_MOVE,
- UNIT_SHOOT,
- UNIT_BUILD,
- SHOW_TERRAIN,
- SHOW_GRID,
- SHOW_UNITS,
- SHOW_NAMES,
- SHOW_FEATURE_NAMES,
- SHOW_NUMBERS,
- SHOW_PEOPLE,
- SHOW_ELEV,
- SHOW_TEMP,
- SHOW_ALL,
- SHOW_MORE,
- COLR_UNITS,
- COLR_TERR,
- COLR_EMBL,
- MONO_REVERSE,
- ZOOM_OUT,
- ZOOM_IN,
- numcontrols
- };
-
- /* Tools govern the interpretation of mouse clicks in a map view. */
-
- enum tooltypes {
- looktool,
- movetool,
- unitmovetool,
- unitshoottool,
- unitbuildtool,
- #ifdef DESIGNERS
- terrainpainttool,
- unitaddtool,
- peoplepainttool,
- featurepainttool,
- #endif /* DESIGNERS */
- numtools
- };
-
- /* The user interface substructure. This is only allocated for sides with
- attached displays. */
-
- typedef struct a_ui {
- Display *dpy; /* The X display used by this side */
- int active; /* True when the display is usable */
- int screen; /* The X screen in use */
- Widget shell; /* Main shell for this side's displays */
- Window rootwin; /* The root window */
- Pixel foreground;
- Pixel background;
- String geospec;
- int mpTime; /* # of milliseconds to pause between mplayer moves */
- Atom kill_atom;
- short bonw; /* true if display is black-on-white */
- short followaction; /* move to where a change has occured */
- short mayseeall;
- int sxdown, sydown;
- int cellx, celly;
- Boolean cellxy_ok; /* cellx & celly valid? */
- struct a_map *mapdown;
- int beepcount; /* number of times we've been beeped */
- /* Constructed during display init. */
- short monochrome; /* obvious */
- short fw, fh; /* dimensions of text font (in pixels) */
- /* Working variables for the display. */
- long bgcolor; /* background color */
- long fgcolor; /* foreground (text) color */
- long whitecolor; /* actual white for this display */
- long blackcolor; /* actual black for this display */
- long enemycolor; /* color for them (usually red) */
- long neutcolor; /* color for fencesitters (usually gray) */
- long graycolor; /* color for graying out (usually gray) */
- long diffcolor; /* unusual/distinct color (usually maroon) */
- long goodcolor; /* color for OKness (usually green) */
- long badcolor; /* color for non-OKness (usually red) */
- long gridcolor;
- long unseencolor;
- long cellcolor[MAXTTYPES]; /* the color of each terrain type */
- long cellfgcolor[MAXTTYPES]; /* the "fg" color of each terrain type */
- long colors[MAXSIDES][3];
- int numcolors[MAXSIDES];
- long *unitcolors;
- long *numunitcolors;
- short dflt_color_unit_images;
- short dflt_color_terr_images;
- short dflt_color_embl_images;
- GC gc; /* a tmp graphics context for this display */
- GC textgc; /* foreground on background text */
- GC ltextgc; /* foreground on background text */
- GC terrgc; /* terrain display gc */
- GC unitgc; /* unit display gc */
- GC emblgc; /* emblem display gc */
- XFontStruct *textfont; /* Font for text display */
- /* Map-related slots. */
- struct a_map *maps; /* Chain of maps that are up */
- /* Help-related slots. */
- Widget help_shell;
- Widget help_form;
- Widget help_topicPort;
- Widget help_topicList;
- Widget help_title;
- Widget help_text;
- Widget help_button_box;
- Widget help_next;
- Widget help_prev;
- Widget help_back;
- Widget help_close;
- short helpw, helph;
- struct a_helpnode *curhelpnode;
- struct a_helpnode **nodestack;
- int nodenumber, nodestackpos;
- #ifdef DESIGNERS
- /* Design-related slots. */
- Widget design_shell;
- Widget design;
- Widget normal_button;
- Widget normal_label;
- Widget terrain_button;
- Widget terrain_label;
- Widget unit_button;
- Widget unit_label;
- Widget people_button;
- Widget people_label;
- Widget feature_button;
- Widget feature_label;
- Widget brush_radius_label;
- short curdesigntool;
- short curbrushradius;
- short curttype;
- short curbgttype;
- short curutype;
- short curusidenumber;
- short cursidenumber;
- short curfid;
- #endif /* DESIGNERS */
- /* Arrays of image families for units, terrain, and sides. */
- ImageFamily **uimages;
- ImageFamily **timages;
- ImageFamily **eimages;
- /* Terrain drawing machinery */
- enum whattouse usewhat[NUMPOWERS][MAXTTYPES];
- /* (should use as cache of image in image family - calc as needed) */
- Pixmap terrpics[NUMPOWERS][MAXTTYPES];
- char terrchars[NUMPOWERS][MAXTTYPES];
- XFontStruct *terrfonts[NUMPOWERS][MAXTTYPES];
- Pixmap hexpics[NUMPOWERS], bhexpics[NUMPOWERS];
- Pixmap hexchars[NUMPOWERS], bhexchars[NUMPOWERS];
- XFontStruct *hexfonts[NUMPOWERS], *bhexfonts[NUMPOWERS];
- /* Unit drawing machinery */
- Pixmap unitpics[NUMPOWERS][MAXUTYPES];
- Pixmap unitmasks[NUMPOWERS][MAXUTYPES];
- char unitchars[NUMPOWERS][MAXUTYPES];
- XFontStruct *unitfonts[NUMPOWERS][MAXUTYPES];
- XFontStruct *unitfont; /* font for unit characters */
- int unitw[NUMPOWERS][MAXUTYPES], unith[NUMPOWERS][MAXUTYPES];
- /* Emblem drawing machinery */
- Pixmap emblempics[MAXSIDES];
- Pixmap emblemmasks[MAXSIDES];
- int embw[MAXSIDES], embh[MAXSIDES];
- /* Map legend drawing machinery */
- XFontStruct *ulegendfonts[NUMPOWERS][MAXUTYPES];
- XFontStruct *flegendfonts[6];
- Font flegendfids[6];
- Legend *legends;
- int numfeatures;
- /* Random stuff */
- Pixmap bombpics[4];
- Pixmap hitpics[3];
- Pixmap controlpics[numcontrols];
- Pixmap toolcursors[numtools];
- Pixmap unitcursors[MAXUTYPES];
- Pixmap boxcurs, boxmask;
- Pixmap grays[numgrays];
- } UI;
-
- /* Each side can open up any number and shape of maps. */
-
- /* All the maps will share colors and bitmaps though. */
-
- typedef struct a_map {
- /* Widgets that make up the map. */
- Widget mainwidget;
- Widget leftpane; /* lefthand area of window */
- Widget leftform; /* */
- Widget rightpane; /* righthand area of window */
- Widget infoform; /* parts of leftform */
- Widget controlform; /* parts of leftform */
- Widget *controls; /* Array of controls */
- Widget mapform; /* parts of leftform */
- Widget sideform; /* parts of rightform */
- Widget info; /* Info about current pos/unit */
- Widget porthole;
- Widget portlabel;
- Widget gamedate; /* Overall game info */
- Widget gameclock; /* overall game info */
- Widget msgarea; /* miscellaneous info related to UI */
- Widget sides; /* List of sides */
- Widget history; /* Place for notices/warnings */
- Widget promptlabel;
- Widget listview;
- Widget listform;
- Widget *list_buttons; /* numutypes+1 of these */
- Widget pannerbox;
- Widget panner;
- Widget help_pop;
- Widget ctrlpanel_pop; /* View control popup */
- Widget ctrlpanel_shell; /* View control popup's shell */
- Widget ctrlpanel_form;
- Widget *ctrlpanel_buttons; /* Array of buttons */
- /* Raw windows that we draw into directly. */
- Window infowin; /* info about a unit and/or cell */
- Pixmap viewwin; /* actual graphical display of an area */
- Window sideswin; /* list of sides */
- /* How to draw the map. */
- short seeall; /* True if viewing world data directly */
- short drawterrain; /* Display solid color terrain on the map? */
- short drawgrid; /* Draw outlines around cells? */
- short drawcellpats; /* Draw terrain patterns? */
- short drawunits; /* Display units on the map? */
- short drawnames; /* Display unit names/numbers on the map? */
- short drawfeatureboundaries;
- short drawfeaturenames; /* true if displaying names of features */
- short oldesttoshow; /* the relative time of the oldest data */
- short agetofade; /* point at which to gray out the display */
- short newesttoshow; /* the relative time of the newest data */
- short fadeterrain; /* fade world features as well as units? */
- short lowestlevel; /* the lowest level of units to display */
- short highestlevel; /* the highest level of units to display */
- short drawpeople; /* true if displaying people sides */
- short drawelevations; /* true if display elevations */
- short drawresources[MAXMTYPES];
- short drawtemp;
- short drawweather;
- short use_color_unit_images;
- short use_color_terr_images;
- short use_color_embl_images;
- short fullpanel;
- /* Slots used for internal display calculations. */
- VP *vp; /* This map's generic view parameters */
- short totalw, totalh; /* Total size of window in pixels */
- short leftfrac;
- short leftw;
- short pxw, pxh; /* Size of map subwindow in pixels */
- short toph;
- short infoh;
- short list1frac;
- short list1w, list1h;
- short list2w, list2h;
- short panw, panh;
- short vx, vy; /* lower left of viewport in cell coords */
- short vw, vh; /* Boundaries of viewport in cell coords */
- short vw2, vh2; /* 1/2 (rounded down) of above values */
- short sidespacing; /* Vertical space for each side in side list */
- short last_num_in_play[MAXUTYPES];
- short last_num_incomplete[MAXUTYPES];
- /* Interaction controls. */
- short curtool; /* Interpretation of left-mouse clicks */
- short curx, cury; /* Current spot being looked at */
- struct a_unit *curunit; /* Unit under cursor */
- short savedcurx, savedcury; /* Current spot being looked at (saved) */
- struct a_unit *savedcurunit;/* Unit under cursor (saved) */
- void (*modalhandler) PROTO ((Side *side, struct a_map *map, int cancelled));
- char inpch; /* Keyboard char */
- short inptype; /* Unit type clicked in unit type list */
- short argint; /* numerical prefix argument */
- short argunitid; /* should be unit id for safety */
- struct a_side *argside;
- short uvec[MAXUTYPES]; /* vector of allowed unit types to input */
- char ustr[MAXUTYPES]; /* used in composing unit type hints */
- short tvec[MAXTTYPES]; /* vector of allowed terrain types to input */
- char tstr[MAXTTYPES]; /* used in composing terrain type hints */
- char prompt[BUFSIZE];
- char answer[BUFSIZE];
- int tmpint;
- /* Link to the next map. */
- struct a_map *next;
- } Map;
-
- /* Iteration over all of a side's map windows. */
-
- #define for_all_maps(s,m) \
- for ((m) = (s)->ui->maps; (m) != NULL; (m) = (m)->next)
-
- #define num_unit_colors(s,s2,u) \
- (((s)->ui->numunitcolors)[numutypes * (s2) + (u)])
-
- #define unit_color(s,s2,u,n) \
- (((s)->ui->numunitcolors)[3 * (numutypes * (s2) + (u)) + (n)])
-
- #define terrain_visible(s,x,y) \
- (g_see_all() || terrain_view((s), wrapx(x), (y)) != UNSEEN)
-
- #define units_visible(s,x,y) \
- (g_see_all() || cover((s), wrapx(x), (y)) > 0)
-
- /* Values shared by all displays and all sides. */
-
- extern Widget thistoplevel;
- extern XtAppContext thisapp;
- extern int nargs;
- extern Arg tmpargs[];
-
- /* Declarations of globally visible functions. */
-
- extern int ask_unit_type PROTO ((Side *side, Map *map, char *prompt,
- int *poss,
- void (*handler)(Side *side, Map *map,
- int cancel)));
- extern int ask_terrain_type PROTO ((Side *side, Map *map, char *prompt,
- int *poss,
- void (*handler)(Side *side, Map *map,
- int cancel)));
- extern void ask_side PROTO ((Side *side, Map *map, char *prompt,
- Side *dflt,
- void (*handler)(Side *side, Map *map,
- int cancel)));
- extern void ask_position PROTO ((Side *side, Map *map, char *prompt,
- void (*handler)(Side *side, Map *map,
- int cancel)));
- extern void ask_bool PROTO ((Side *side, Map *map, char *prompt,
- int dflt, void (*handler)(Side *side, Map *map,
- int cancel)));
- extern void ask_string PROTO ((Side *side, Map *map, char *prompt, char *dflt,
- void (*handler)(Side *side, Map *map,
- int cancel)));
-
- extern int grok_unit_type PROTO ((Side *side, Map *map, int *typep));
- extern int grok_terrain_type PROTO ((Side *side, Map *map, int *typep));
- extern int grok_side PROTO ((Side *side, Map *map, Side **side2p));
- extern int grok_position PROTO ((Side *side, Map *map, int *xp, int *yp));
- extern int grok_bool PROTO ((Side *side, Map *map));
- extern int grok_string PROTO ((Side *side, Map *map, char **strp));
-
- extern int xform PROTO ((Side *side, Map *map, int x, int y,
- int *sxp, int *syp));
- extern int x_xform_unit PROTO ((Side *side, Map *map, Unit *unit,
- int *sxp, int *syp, int *swp, int *shp));
- extern int x_xform_unit_self PROTO ((Side *side, Map *map, Unit *unit,
- int *sxp, int *syp, int *swp, int *shp));
- extern int x_xform_occupant PROTO ((Side *side, Map *map,
- Unit *transport, Unit *unit,
- int sx, int sy, int sw, int sh,
- int *sxp, int *syp, int *swp, int *shp));
- extern int x_nearest_cell PROTO ((Side *side, Map *map, int sx, int sy,
- int *xp, int *yp));
- extern int x_nearest_boundary PROTO ((Side *side, Map *map, int sx, int sy,
- int *xp, int *yp, int *dirp));
- extern int x_nearest_unit PROTO ((Side *side, Map *map, int sx, int sy,
- Unit **unitp));
-
- extern void init_x_signal_handlers PROTO ((void));
-
- extern void check_player_displays PROTO ((void));
- extern void init_all_displays PROTO ((void));
- extern void init_redraws PROTO ((void));
- extern void init_display PROTO ((Side *side));
- extern void set_colors PROTO ((Side *side));
- extern long request_color PROTO ((Side *side, char *name));
-
- extern XFontStruct *open_font PROTO ((Side *side, char *name, char *xdefault,
- XFontStruct *altfont, char *alttype,
- Font *fid));
- extern Cursor make_cursor PROTO ((Display *dpy, Window win,
- char *cursbits, char *maskbits,
- unsigned long fg, unsigned long bg,
- unsigned int x, unsigned int y));
-
- extern void reset_color_state PROTO ((Side *side));
- extern void reset_window_colors PROTO ((Side *side, Window win));
-
- extern void execute_command PROTO ((Side *side, Map *map));
-
- extern void set_current_unit PROTO ((Side *side, Map *map, Unit *unit));
- extern void set_current_xy PROTO ((Side *side, Map *map, int x, int y));
- extern void clear_current PROTO ((Side *side, Map *map));
- extern void save_cur PROTO ((Side *side, Map *map));
- extern void restore_cur PROTO ((Side *side, Map *map));
-
- extern Map *create_map PROTO ((Side *side, int power, char *geospec));
-
- extern void add_map_actions PROTO ((void));
-
- extern void set_tool_cursor PROTO ((Side *side, Map *map));
-
- extern void set_map_power PROTO ((Side *side, Map *map, int power));
- extern void x_center_on_focus PROTO ((Side *side, Map *map));
-
- extern void handle_key_event PROTO ((Side *side, Map *map, XEvent *evt));
-
- extern int find_side_and_map PROTO ((Widget w, Side **sidep, Map **mapp));
- extern int find_side_and_map_via_control PROTO ((Widget w,
- Side **sidep, Map **mapp));
- extern int find_side_and_map_via_listform PROTO ((Widget w,
- Side **sidep, Map **mapp));
- extern int find_side_and_map_via_mapform PROTO ((Widget w,
- Side **sidep, Map **mapp));
- extern int find_side_and_map_via_rightform PROTO ((Widget w,
- Side **sidep, Map **mapp));
- extern int find_side_and_map_via_a_toplevel PROTO ((Widget w,
- Side **sidep, Map **mapp));
- extern int find_side_and_map_via_porthole PROTO ((Widget w,
- Side **sidep, Map **mapp));
- extern int find_side_via_widget PROTO ((Widget w, Side **sidep));
-
- extern void update_controls PROTO ((Side *side, Map *map));
-
- extern void draw_all_maps PROTO ((Side *side));
-
- extern void draw_map PROTO ((Side *side, Map *map));
- extern void draw_map_view PROTO ((Side *side, Map *map));
- extern void destroy_map PROTO ((Side *side, Map *map));
-
-
- extern void draw_row PROTO ((Side *side, Map *map,
- int x0, int y0, int len, int clearit));
- extern void draw_unit_image PROTO ((Side *side, Window win,
- int sx, int sy, int sw, int sh,
- int u, int s2, int fg, int bg));
- extern void draw_side_emblem PROTO ((Side *side, Window win,
- int ex, int ey, int ew, int eh,
- int s2, int style));
- extern void draw_current PROTO ((Side *side, Map *map));
- extern void erase_current PROTO ((Side *side, Map *map, int x, int y,
- Unit *unit));
-
- extern void draw_prompt PROTO ((Side *side, Map *map));
- extern void clear_prompt PROTO ((Side *side, Map *map));
- extern void draw_map_info PROTO ((Side *side, Map *map));
- extern void draw_game_state PROTO ((Side *side, Map *map));
- extern void draw_game_clocks PROTO ((Side *side, Map *map));
- extern void draw_map_sides PROTO ((Side *side, Map *map));
- extern void draw_side_info PROTO ((Side *side, Map *map, Side *side2));
- extern void draw_side_progress PROTO ((Side *side, Map *map, Side *side2));
-
- extern void put_on_screen PROTO ((Side *side, Map *map, int x, int y));
- extern int in_middle PROTO ((Side *side, Map *map, int x, int y));
-
- extern void move_the_selected_unit PROTO ((Side *side, Map *map, Unit *unit,
- int sx, int sy));
-
- extern void create_help PROTO ((Side *side));
- extern void popup_help PROTO ((Side *side));
- extern void popdown_help PROTO ((Side *side));
-
- extern void recenter PROTO ((Side *side, Map *map, int x, int y));
-
- extern void draw_text PROTO ((Side *side, Window win, int x, int y,
- char *str,int color));
- extern void draw_fg_text PROTO ((Side *side, Window win, int x, int y,
- char *str));
-
- extern void textw_printf PROTO ((const Widget w, const char *fmt, ...));
-
- extern int font_width PROTO ((XFontStruct *font));
- extern int font_height PROTO ((XFontStruct *font));
-
- extern void close_display PROTO ((Side *side));
-
- extern void exit_xconq PROTO ((Side *side));
-
- extern void notify_all PROTO ((char *fmt, ...));
- extern void low_notify PROTO ((Side *side, char *str));
- extern void redraw PROTO ((Side *side));
- extern void flush_output PROTO ((Side *side));
- extern void beep PROTO ((Side *side));
-
- extern void flush_input PROTO ((Side *side));
-
- extern void build_name PROTO ((char *name, char *first, char *second));
-
- extern void draw_view_in_panner PROTO ((Side *side, Map *map));
-
- extern void set_message_area PROTO ((Map *map, char *msg));
-
- extern void add_map_actions PROTO ((void));
-
- extern void update_unit_type_list PROTO ((Side *side, Map *map, int u));
-
- extern XawTextPosition widget_text_length PROTO ((Widget w));
-
- extern void move_caret_to_end PROTO ((Widget w));
-
- extern int popup_print_setup_dialog PROTO ((Side *side, PrintParameters *ps_pp));
-
- extern int num_features PROTO ((void));
- void place_legends PROTO ((Side *side));
-
- /* Declarations of all the command functions. */
-
- #undef DEF_CMD
- #define DEF_CMD(letter,name,args,FN,help) \
- void FN PROTO ((Side *side, Map *map));
-
- #include "cmd.def"
-
- #include "xcmd.def"
-
- #ifdef DESIGNERS
- extern void create_design PROTO ((Side *side));
- extern void popup_design PROTO ((Side *side));
- extern void update_curttype PROTO ((Side *side));
- extern void update_curutype PROTO ((Side *side));
- extern void update_cursidenumber PROTO ((Side *side));
- extern void update_curfeature PROTO ((Side *side));
- extern void update_curbrushradius PROTO ((Side *side));
- extern void set_designer_cur_from_map PROTO ((Side *side, Map *map,
- int sx, int sy));
- extern void handle_designer_map_click PROTO ((Side *side, Map *map,
- int sx, int sy));
- extern void popdown_design PROTO ((Side *side));
- #endif /* DESIGNERS */
-